#ifndef CFILESCANNER_H
#define CFILESCANNER_H

#include <iostream>
#include <string>
#include <queue>
#include <pthread.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>

class _i_scan_notify {
public:
    virtual bool on_begin_scan() = 0;
    virtual bool on_end_scan() = 0;
    virtual bool on_file(const char* lpszfile) = 0;
    virtual bool on_directory(const char* lpszPath) = 0;
};

class CFileScanner {
public:
    CFileScanner();
    ~CFileScanner();

    void set_notify(_i_scan_notify* p);
    void add_path(const char* lpszPath);
    void clear();
    void stop();
    bool scan(bool recursive);
   bool start_scan_thread(bool recursive); // 添加的声明
private:
    bool scan(const char* lpszPath, bool recursive);

    std::queue<std::string> _M_dir_queue;
    _i_scan_notify* _M_notify;
    volatile bool _M_b_stopped;
    pthread_mutex_t _M_lock;
    int _M_file_count;
    int _M_dir_count;
    pthread_t scan_thread;

    static void* ScanThreadFunc(void* arg);
};

#endif // CFILESCANNER_H
